<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        .box {
            width: 600px;
            text-align: center;
            margin: 50px auto;
        }

        button {
            font-size: 16px;
            padding: 10px 30px;
            margin: 30px;
        }

        .lottery_ticket {
            width: 600px;
            height: 200px;
            background-color: orangered;
            color: #fff;
            font-size: 40px;
            text-align: center;
            line-height: 200px;
        }
    </style>
</head>

<body>
    <div class='box'>
        <button>生成彩票</button>
        <div class='lottery_ticket'>请抽取彩票</div>
    </div>
    <script>
        var str = window.location.href;
        var btn = document.querySelector("button");
        var ticket = document.querySelector(".lottery_ticket");
        var json = {};
        btn.onclick = function () {
            //Math.random()取随机值和new Date().getTime()获取时间戳会取到不重复的值
            var num = new Date().getTime();
            window.location.hash = num;
            json[num] = Randow();
        }
        window.onhashchange = function () {
            ticket.innerHTML = window.location.href === str ? "请重新抽取彩票" : json[window.location.hash.substring(1)];
        };

        function Randow() {
            var arr = [];
            for (var i = 0; i < 28; i++) {
                arr.push(i + 1);
            }
            arr.sort(function (a, b) {
                return Math.random() - 0.5;
            });
            arr.length = 7;
            return arr;
        }
    </script>
</body>

</html>